package com.zhaolang.qogir.ui.processed;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.suke.widget.SwitchButton;
import com.zhaolang.qogir.R;
import com.zhaolang.qogir.ui.BaseFragment;
import com.zhaolang.qogir.ui.TitleView;
import com.zhaolang.qogir.ui.adapter.FragmentProcessedAdapter;

public class FragmentProcessed extends BaseFragment implements View.OnClickListener {
    private TitleView mTitle;
    private View rootView;
    private ViewPager viewPager;
    private TabLayout tabLayout;
    public static final String TAG = "FragmentProcessed";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(container, savedInstanceState);
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.fragment_processed, null);
            init_view();
        }
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView(rootView);
        }
        return rootView;
    }

    private void init_view() {
        View title = rootView.findViewById(R.id.vg_title);
        mTitle = new TitleView(getContext(), title);
        mTitle.setCenterText(R.string.title_main_processed, this);
        mTitle.setTextColor(mContext.getResources().getColor(R.color.white));

        tabLayout = (TabLayout) rootView.findViewById(R.id.tl);
        viewPager = rootView.findViewById(R.id.viewPager);
        viewPager.setAdapter(new FragmentProcessedAdapter(getFragmentManager()));
        tabLayout.setupWithViewPager(viewPager);

        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                Log.i(TAG, "onTabSelected:" + tab.getText());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });
    }

    @Override
    public void onClick(View v) {
    }
}
